package b.b.h;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.SeekBar;
import b.b.b;
import b.i.b.f;
import b.i.k.o;
import java.util.WeakHashMap;

/* compiled from: AppCompatSeekBarHelper */
public class h extends g {
    public final SeekBar d;
    public Drawable e;
    public ColorStateList f = null;
    public Mode g = null;
    public boolean h = false;
    public boolean i = false;

    public h(SeekBar seekBar) {
        super(seekBar);
        this.d = seekBar;
    }

    public void a(AttributeSet attributeSet, int i) {
        super.a(attributeSet, i);
        Context context = this.d.getContext();
        int[] iArr = b.g;
        f0 q = f0.q(context, attributeSet, iArr, i, 0);
        SeekBar seekBar = this.d;
        o.o(seekBar, seekBar.getContext(), iArr, attributeSet, q.b, i, 0);
        Drawable h = q.h(0);
        if (h != null) {
            this.d.setThumb(h);
        }
        Drawable g = q.g(1);
        Drawable drawable = this.e;
        if (drawable != null) {
            drawable.setCallback(null);
        }
        this.e = g;
        if (g != null) {
            g.setCallback(this.d);
            seekBar = this.d;
            WeakHashMap weakHashMap = o.a;
            f.X0(g, seekBar.getLayoutDirection());
            if (g.isStateful()) {
                g.setState(this.d.getDrawableState());
            }
            c();
        }
        this.d.invalidate();
        if (q.o(3)) {
            this.g = o.c(q.j(3, -1), this.g);
            this.i = true;
        }
        if (q.o(2)) {
            this.f = q.c(2);
            this.h = true;
        }
        q.b.recycle();
        c();
    }

    public final void c() {
        Drawable drawable = this.e;
        if (drawable == null) {
            return;
        }
        if (this.h || this.i) {
            drawable = f.k1(drawable.mutate());
            this.e = drawable;
            if (this.h) {
                drawable.setTintList(this.f);
            }
            if (this.i) {
                this.e.setTintMode(this.g);
            }
            if (this.e.isStateful()) {
                this.e.setState(this.d.getDrawableState());
            }
        }
    }

    public void d(Canvas canvas) {
        if (this.e != null) {
            int max = this.d.getMax();
            int i = 1;
            if (max > 1) {
                int intrinsicWidth = this.e.getIntrinsicWidth();
                int intrinsicHeight = this.e.getIntrinsicHeight();
                intrinsicWidth = intrinsicWidth >= 0 ? intrinsicWidth / 2 : 1;
                if (intrinsicHeight >= 0) {
                    i = intrinsicHeight / 2;
                }
                this.e.setBounds(-intrinsicWidth, -i, intrinsicWidth, i);
                float width = ((float) ((this.d.getWidth() - this.d.getPaddingLeft()) - this.d.getPaddingRight())) / ((float) max);
                intrinsicWidth = canvas.save();
                canvas.translate((float) this.d.getPaddingLeft(), (float) (this.d.getHeight() / 2));
                for (intrinsicHeight = 0; intrinsicHeight <= max; intrinsicHeight++) {
                    this.e.draw(canvas);
                    canvas.translate(width, 0.0f);
                }
                canvas.restoreToCount(intrinsicWidth);
            }
        }
    }
}
